package week_1;

import toolPackage.ListNode;

public class day06_week1 {
    public static void main(String[] args) {
        ListNode $_1=new ListNode(1);
        ListNode $1_2=new ListNode(2);
        ListNode $2_3=new ListNode(3);
        $_1.next=$1_2;
        $1_2.next=$2_3;
        System.out.println($_1);
        System.out.println(removeElements($_1,3));
    }

    /**
     * 思路:
     * 1.遍历整个链
     * 2.找到要删除的所有链
     * 3.返回头链
     *
     * 可能遇到的问题:
     * 1.要删除的链是头部
     * @param head
     * @param val
     * @return
     */
    public static ListNode removeElements(ListNode head, int val) {
        ListNode head1=new ListNode(0);
        head1.next=head;
        ListNode head0=head1;
        for (;head0.next!=null;){
            if (head0.next.val==val){
                head0.next=head0.next.next;
            }else {
                head0=head0.next;
            }
        }
        return head1.next;
    }
}
